home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / program / gmp202.zip / gmp.info-1 (.txt) < prev    next >
GNU Info File  |  1996-06-06  |  51KB  |  947 lines

  1. This is Info file gmp.info, produced by Makeinfo-1.64 from the input
  2. file gmp.texi.
  3. START-INFO-DIR-ENTRY
  4. * gmp: (gmp.info).               GNU Multiple Precision Arithmetic Library.
  5. END-INFO-DIR-ENTRY
  6.    This file documents GNU MP, a library for arbitrary-precision
  7. arithmetic.
  8.    Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation,
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that
  14. the entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20. File: gmp.info,  Node: Top,  Next: Copying,  Prev: (dir),  Up: (dir)
  21. GNU MP
  22. ******
  23.    This manual documents how to install and use the GNU multiple
  24. precision arithmetic library, version 2.0.2.
  25. * Menu:
  26. * Copying::                   GMP Copying Conditions (LGPL).
  27. * Introduction to MP::        Brief introduction to GNU MP.
  28. * Installing MP::             How to configure and compile the MP library.
  29. * MP Basics::                 What every MP user should now.
  30. * Reporting Bugs::            How to usefully report bugs.
  31. * Integer Functions::         Functions for arithmetic on signed integers.
  32. * Rational Number Functions:: Functions for arithmetic on rational numbers.
  33. * Floating-point Functions::  Functions for arithmetic on floats.
  34. * Low-level Functions::       Fast functions for natural numbers.
  35. * BSD Compatible Functions::  All functions found in BSD MP.
  36. * Custom Allocation::         How to customize the internal allocation.
  37. * Contributors::
  38. * References::
  39. * Concept Index::
  40. * Function Index::
  41. File: gmp.info,  Node: Copying,  Next: Introduction to MP,  Prev: Top,  Up: Top
  42. GNU MP Copying Conditions
  43. *************************
  44.    This library is "free"; this means that everyone is free to use it
  45. and free to redistribute it on a free basis.  The library is not in the
  46. public domain; it is copyrighted and there are restrictions on its
  47. distribution, but these restrictions are designed to permit everything
  48. that a good cooperating citizen would want to do.  What is not allowed
  49. is to try to prevent others from further sharing any version of this
  50. library that they might get from you.
  51.    Specifically, we want to make sure that you have the right to give
  52. away copies of the library, that you receive source code or else can
  53. get it if you want it, that you can change this library or use pieces
  54. of it in new free programs, and that you know you can do these things.
  55.    To make sure that everyone has such rights, we have to forbid you to
  56. deprive anyone else of these rights.  For example, if you distribute
  57. copies of the GNU MP library, you must give the recipients all the
  58. rights that you have.  You must make sure that they, too, receive or
  59. can get the source code.  And you must tell them their rights.
  60.    Also, for our own protection, we must make certain that everyone
  61. finds out that there is no warranty for the GNU MP library.  If it is
  62. modified by someone else and passed on, we want their recipients to
  63. know that what they have is not what we distributed, so that any
  64. problems introduced by others will not reflect on our reputation.
  65.    The precise conditions of the license for the GNU MP library are
  66. found in the Library General Public License that accompany the source
  67. code.
  68. File: gmp.info,  Node: Introduction to MP,  Next: Installing MP,  Prev: Copying,  Up: Top
  69. Introduction to GNU MP
  70. **********************
  71.    GNU MP is a portable library written in C for arbitrary precision
  72. arithmetic on integers, rational numbers, and floating-point numbers.
  73. It aims to provide the fastest possible arithmetic for all applications
  74. that need higher precision than is directly supported by the basic C
  75. types.
  76.    Many applications use just a few hundred bits of precision; but some
  77. applications may need thousands or even millions of bits.  MP is
  78. designed to give good performance for both, by choosing algorithms
  79. based on the sizes of the operands, and by carefully keeping the
  80. overhead at a minimum.
  81.    The speed of MP is achieved by using fullwords as the basic
  82. arithmetic type, by using sophisticated algorithms, by including
  83. carefully optimized assembly code for the most common inner loops for
  84. many different CPUs, and by a general emphasis on speed (as opposed to
  85. simplicity or elegance).
  86.    There is carefully optimized assembly code for these CPUs: DEC
  87. Alpha, Amd 29000, HPPA 1.0 and 1.1, Intel Pentium and generic x86,
  88. Intel i960, Motorola MC68000, MC68020, MC88100, and MC88110,
  89. Motorola/IBM PowerPC, National NS32000, IBM POWER, MIPS R3000, R4000,
  90. SPARCv7, SuperSPARC, generic SPARCv8, and DEC VAX.  Some optimizations
  91. also for ARM, Clipper, IBM ROMP (RT), and Pyramid AP/XP.
  92.    This version of MP is released under a more liberal license than
  93. previous versions.  It is now permitted to link MP to non-free
  94. programs, as long as MP source code is provided when distributing the
  95. non-free program.
  96. How to use this Manual
  97. ======================
  98.    Everyone should read *Note MP Basics::.  If you need to install the
  99. library yourself, you need to read *Note Installing MP::, too.
  100.    The rest of the manual can be used for later reference, although it
  101. is probably a good idea to glance through it.
  102. File: gmp.info,  Node: Installing MP,  Next: MP Basics,  Prev: Introduction to MP,  Up: Top
  103. Installing MP
  104. *************
  105.    To build MP, you first have to configure it for your CPU and
  106. operating system.  You need a C compiler, preferably GCC, but any
  107. reasonable compiler should work.  And you need a standard Unix `make'
  108. program, plus some other standard Unix utility programs.
  109.    (If you're on an MS-DOS machine, your can build MP using `make.bat'.
  110. It requires that djgpp is installed.  It does not require
  111. configuration, nor is `make' needed; `make.bat' both configures and
  112. builds the library.)
  113.    Here are the steps needed to install the library on Unix systems:
  114.   1. In most cases, `./configure --target=cpu-vendor-os', should work
  115.      both for native and cross-compilation.  If you get error messages,
  116.      your machine might not be supported.
  117.      If you want to compile in a separate object directory, cd to that
  118.      directory, and prefix the configure command with the path to the
  119.      MP source directory.  Not all `make' programs have the necessary
  120.      features to support this.  In particular, SunOS and Slowaris
  121.      `make' have bugs that makes them unable to build from a separate
  122.      object directory.  Use GNU `make' instead.
  123.      In addition to the standard cpu-vendor-os tuples, MP recognizes
  124.      sparc8 and supersparc as valid CPU names.  Specifying these CPU
  125.      names for relevant systems will improve performance significantly.
  126.      In general, if you want a library that runs as fast as possible,
  127.      you should make sure you configure MP for the exact CPU type your
  128.      system uses.
  129.      If you have `gcc' in your `PATH', it will be used by default.  To
  130.      override this, pass `-with-gcc=no' to `configure'.
  131.   2. `make'
  132.      This will compile MP, and create a library archive file `libgmp.a'
  133.      in the working directory.
  134.   3. `make check'
  135.      This will make sure MP was built correctly.  If you get error
  136.      messages, please report this to `bug-gmp@prep.ai.mit.edu'.  (*Note
  137.      Reporting Bugs::, for information on what to include in useful bug
  138.      reports.)
  139.   4. `make install'
  140.      This will copy the file `gmp.h' and `libgmp.a', as well as the info
  141.      files, to `/usr/local' (or if you passed the `--prefix' option to
  142.      `configure', to the directory given as argument to `--prefix').
  143. If you wish to build and install the BSD MP compatible functions, use
  144. `make libmp.a' and `make install-bsdmp'.
  145.    There are some other useful make targets:
  146.    * `doc'
  147.      Create a DVI version of the manual, in `gmp.dvi' and a set of info
  148.      files, in `gmp.info', `gmp.info-1', `gmp.info-2', etc.
  149.    * `ps'
  150.      Create a Postscript version of the manual, in `gmp.ps'.
  151.    * `html'
  152.      Create a HTML version of the manual, in `gmp.html'.
  153.    * `clean'
  154.      Delete all object files and archive files, but not the
  155.      configuration files.
  156.    * `distclean'
  157.      Delete all files not included in the distribution.
  158.    * `uninstall'
  159.      Delete all files copied by `make install'.
  160. Known Build Problems
  161. ====================
  162.    GCC 2.7.2 (as well as 2.6.3) for the RS/6000 and PowerPC can not be
  163. used to compile MP, due to a bug in GCC.  If you want to use GCC for
  164. these machines, you need to apply the patch below to GCC, or use a
  165. later version of the compiler.
  166.    If you are on a Sequent Symmetry, use the GNU assembler instead of
  167. the system's assembler, since the latter has serious bugs.
  168.    The system compiler on NeXT is a massacred and old gcc, even if the
  169. compiler calls itself `cc'.  This compiler cannot be used to build MP.
  170. You need to get a real gcc, and install that before you compile MP.
  171. (NeXT might have fixed this in newer releases of their system.)
  172.    The system C compiler under SunOS 4 has a bug that makes it
  173. miscompile mpq/get_d.c.  This will make `make check' fail.
  174.    Please report other problems to `bug-gmp@prep.ai.mit.edu'.  *Note
  175. Reporting Bugs::.
  176.    Patch to apply to GCC 2.6.3 and 2.7.2:
  177.      *** config/rs6000/rs6000.md    Sun Feb 11 08:22:11 1996
  178.      --- config/rs6000/rs6000.md.new    Sun Feb 18 03:33:37 1996
  179.      ***************
  180.      *** 920,926 ****
  181.           (set (match_operand:SI 0 "gpc_reg_operand" "=r")
  182.            (not:SI (match_dup 1)))]
  183.          ""
  184.      !   "nor. %0,%2,%1"
  185.          [(set_attr "type" "compare")])
  186.      
  187.        (define_insn ""
  188.      --- 920,926 ----
  189.           (set (match_operand:SI 0 "gpc_reg_operand" "=r")
  190.            (not:SI (match_dup 1)))]
  191.          ""
  192.      !   "nor. %0,%1,%1"
  193.          [(set_attr "type" "compare")])
  194.      
  195.        (define_insn ""
  196. File: gmp.info,  Node: MP Basics,  Next: Reporting Bugs,  Prev: Installing MP,  Up: Top
  197. MP Basics
  198. *********
  199.    All declarations needed to use MP are collected in the include file
  200. `gmp.h'.  It is designed to work with both C and C++ compilers.
  201. Nomenclature and Types
  202. ======================
  203. In this manual, "integer" usually means a multiple precision integer, as
  204. defined by the MP library.  The C data type for such integers is
  205. `mpz_t'.  Here are some examples of how to declare such integers:
  206.      mpz_t sum;
  207.      
  208.      struct foo { mpz_t x, y; };
  209.      
  210.      mpz_t vec[20];
  211. "Rational number" means a multiple precision fraction.  The C data type
  212. for these fractions is `mpq_t'.  For example:
  213.      mpq_t quotient;
  214. "Floating point number" or "Float" for short, is an arbitrary precision
  215. mantissa with an limited precision exponent.  The C data type for such
  216. objects is `mpf_t'.
  217. A "limb" means the part of a multi-precision number that fits in a
  218. single word.  (We chose this word because a limb of the human body is
  219. analogous to a digit, only larger, and containing several digits.)
  220. Normally a limb contains 32 or 64 bits.  The C data type for a limb is
  221. `mp_limb_t'.
  222. Function Classes
  223. ================
  224.    There are six classes of functions in the MP library:
  225.   1. Functions for signed integer arithmetic, with names beginning with
  226.      `mpz_'.  The associated type is `mpz_t'.  There are about 100
  227.      functions in this class.
  228.   2. Functions for rational number arithmetic, with names beginning with
  229.      `mpq_'.  The associated type is `mpq_t'.  There are about 20
  230.      functions in this class, but the functions in the previous class
  231.      can be used for performing arithmetic on the numerator and
  232.      denominator separately.
  233.   3. Functions for floating-point arithmetic, with names beginning with
  234.      `mpf_'.  The associated type is `mpf_t'.  There are about 50
  235.      functions is this class.
  236.   4. Functions compatible with Berkeley MP, such as `itom', `madd', and
  237.      `mult'.  The associated type is `MINT'.
  238.   5. Fast low-level functions that operate on natural numbers.  These
  239.      are used by the functions in the preceding groups, and you can
  240.      also call them directly from very time-critical user programs.
  241.      These functions' names begin with `mpn_'.  There are about 30
  242.      (hard-to-use) functions in this class.
  243.      The associated type is array of `mp_limb_t'.
  244.   6. Miscellaneous functions.  Functions for setting up custom
  245.      allocation.
  246. MP Variable Conventions
  247. =======================
  248.    As a general rule, all MP functions expect output arguments before
  249. input arguments.  This notation is based on an analogy with the
  250. assignment operator.  (The BSD MP compatibility functions disobey this
  251. rule, having the output argument(s) last.)
  252.    MP allows you to use the same variable for both input and output in
  253. the same expression.  For example, the main function for integer
  254. multiplication, `mpz_mul', can be used like this: `mpz_mul (x, x, x)'.
  255. This computes the square of X and puts the result back in X.
  256.    Before you can assign to an MP variable, you need to initialize it
  257. by calling one of the special initialization functions.  When you're
  258. done with a variable, you need to clear it out, using one of the
  259. functions for that purpose.  Which function to use depends on the type
  260. of variable.  See the chapters on integer functions, rational number
  261. functions, and floating-point functions for details.
  262.    A variable should only be initialized once, or at least cleared out
  263. between each initialization.  After a variable has been initialized, it
  264. may be assigned to any number of times.
  265.    For efficiency reasons, avoid to initialize and clear out a variable
  266. in loops.  Instead, initialize it before entering the loop, and clear
  267. it out after the loop has exited.
  268.    You don't need to be concerned about allocating additional space for
  269. MP variables.  All functions in MP automatically allocate additional
  270. space when a variable does not already have enough space.  They do not,
  271. however, reduce the space when a smaller number is stored in the
  272. object.  Most of the time, this policy is best, since it avoids
  273. frequent re-allocation.
  274. Useful Macros and Constants
  275. ===========================
  276.  - Global Constant: const int mp_bits_per_limb
  277.      The number of bits per limb.
  278.  - Macro: __GNU_MP_VERSION
  279.  - Macro: __GNU_MP_VERSION_MINOR
  280.      The major and minor MP version, respectively, as integers.
  281. Compatibility with Version 1.x
  282. ==============================
  283.    This version of MP is upward compatible with previous versions of
  284. MP, with a few exceptions.
  285.   1. Integer division functions round the result differently.  The old
  286.      functions (`mpz_div', `mpz_divmod', `mpz_mdiv', `mpz_mdivmod',
  287.      etc) now all use floor rounding (i.e., they round the quotient to
  288.      -infinity).  There are a lot of new functions for integer
  289.      division, giving the user better control over the rounding.
  290.   2. The function `mpz_mod' now compute the true *mod* function.
  291.   3. The functions `mpz_powm' and `mpz_powm_ui' now use *mod* for
  292.      reduction.
  293.   4. The assignment functions for rational numbers do no longer
  294.      canonicalize their results.  In the case a non-canonical result
  295.      could arise from an assignment, the user need to insert an
  296.      explicit call to `mpq_canonicalize'.  This change was made for
  297.      efficiency.
  298.   5. Output generated by `mpz_out_raw' in this release cannot be read
  299.      by `mpz_inp_raw' in previous releases.  This change was made for
  300.      making the file format truly portable between machines with
  301.      different word sizes.
  302.   6. Several `mpn' functions have changed.  But they were intentionally
  303.      undocumented in previous releases.
  304.   7. The functions `mpz_cmp_ui', `mpz_cmp_si', and `mpq_cmp_ui' are now
  305.      implementated as macros, and thereby sometimes evaluate their
  306.      arguments multiple times.
  307.   8. The functions `mpz_pow_ui' and `mpz_ui_pow_ui' now yield 1 for
  308.      0^0.  (In version 1, they yielded 0.)
  309. Getting the Latest Version of MP
  310. ================================
  311.    The latest version of the MP library is available by anonymous ftp
  312. from from `prep.ai.mit.edu'.  The file name is
  313. `/pub/gnu/gmp-M.N.tar.gz'.  Many sites around the world mirror `prep';
  314. please use a mirror site near you.
  315. File: gmp.info,  Node: Reporting Bugs,  Next: Integer Functions,  Prev: MP Basics,  Up: Top
  316. Reporting Bugs
  317. **************
  318.    If you think you have found a bug in the MP library, please
  319. investigate it and report it.  We have made this library available to
  320. you, and it is not to ask too much from you, to ask you to report the
  321. bugs that you find.
  322.    There are a few things you should think about when you put your bug
  323. report together.
  324.    You have to send us a test case that makes it possible for us to
  325. reproduce the bug.  Include instructions on how to run the test case.
  326.    You also have to explain what is wrong; if you get a crash, or if
  327. the results printed are incorrect and in that case, in what way.
  328.    It is not uncommon that an observed problem is actually due to a bug
  329. in the compiler used when building MP; the MP code tends to explore
  330. interesting corners in compilers.  Therefore, please include compiler
  331. version information in your bug report.  This can be extracted using
  332. `what `which cc`', or, if you're using gcc, `gcc -v'.  Also, include
  333. the output from `uname -a'.
  334.    If your bug report is good, we will do our best to help you to get a
  335. corrected version of the library; if the bug report is poor, we won't
  336. do anything about it (aside of chiding you to send better bug reports).
  337.    Send your bug report to: `bug-gmp@prep.ai.mit.edu'.
  338.    If you think something in this manual is unclear, or downright
  339. incorrect, or if the language needs to be improved, please send a note
  340. to the same address.
  341. File: gmp.info,  Node: Integer Functions,  Next: Rational Number Functions,  Prev: Reporting Bugs,  Up: Top
  342. Integer Functions
  343. *****************
  344.    This chapter describes the MP functions for performing integer
  345. arithmetic.  These functions start with the prefix `mpz_'.
  346.    Arbitrary precision integers are stored in objects of type `mpz_t'.
  347. * Menu:
  348. * Initializing Integers::
  349. * Assigning Integers::
  350. * Simultaneous Integer Init & Assign::
  351. * Converting Integers::
  352. * Integer Arithmetic::
  353. * Comparison Functions::
  354. * Integer Logic and Bit Fiddling::
  355. * I/O of Integers::
  356. * Miscellaneous Integer Functions::
  357. File: gmp.info,  Node: Initializing Integers,  Next: Assigning Integers,  Up: Integer Functions
  358. Initialization and Assignment Functions
  359. =======================================
  360.    The functions for integer arithmetic assume that all integer objects
  361. are initialized.  You do that by calling the function `mpz_init'.
  362.  - Function: void mpz_init (mpz_t INTEGER)
  363.      Initialize INTEGER with limb space and set the initial numeric
  364.      value to 0.  Each variable should normally only be initialized
  365.      once, or at least cleared out (using `mpz_clear') between each
  366.      initialization.
  367.    Here is an example of using `mpz_init':
  368.      {
  369.        mpz_t integ;
  370.        mpz_init (integ);
  371.        ...
  372.        mpz_add (integ, ...);
  373.        ...
  374.        mpz_sub (integ, ...);
  375.      
  376.        /* Unless the program is about to exit, do ... */
  377.        mpz_clear (integ);
  378.      }
  379. As you can see, you can store new values any number of times, once an
  380. object is initialized.
  381.  - Function: void mpz_clear (mpz_t INTEGER)
  382.      Free the limb space occupied by INTEGER.  Make sure to call this
  383.      function for all `mpz_t' variables when you are done with them.
  384.  - Function: void * _mpz_realloc (mpz_t INTEGER, mp_size_t NEW_ALLOC)
  385.      Change the limb space allocation to NEW_ALLOC limbs.  This
  386.      function is not normally called from user code, but it can be used
  387.      to give memory back to the heap, or to increase the space of a
  388.      variable to avoid repeated automatic re-allocation.
  389.  - Function: void mpz_array_init (mpz_t INTEGER_ARRAY[], size_t
  390.           ARRAY_SIZE, mp_size_t FIXED_NUM_BITS)
  391.      Allocate *fixed* limb space for all ARRAY_SIZE integers in
  392.      INTEGER_ARRAY.  The fixed allocation for each integer in the array
  393.      is enough to store FIXED_NUM_BITS.  If the fixed space will be
  394.      insufficient for storing the result of a subsequent calculation,
  395.      the result is unpredictable.
  396.      This function is useful for decreasing the working set for some
  397.      algorithms that use large integer arrays.
  398.      There is no way to de-allocate the storage allocated by this
  399.      function.  Don't call `mpz_clear'!
  400. File: gmp.info,  Node: Assigning Integers,  Next: Simultaneous Integer Init & Assign,  Prev: Initializing Integers,  Up: Integer Functions
  401. Assignment Functions
  402. --------------------
  403.    These functions assign new values to already initialized integers
  404. (*note Initializing Integers::.).
  405.  - Function: void mpz_set (mpz_t ROP, mpz_t OP)
  406.  - Function: void mpz_set_ui (mpz_t ROP, unsigned long int OP)
  407.  - Function: void mpz_set_si (mpz_t ROP, signed long int OP)
  408.  - Function: void mpz_set_d (mpz_t ROP, double OP)
  409.  - Function: void mpz_set_q (mpz_t ROP, mpq_t OP)
  410.  - Function: void mpz_set_f (mpz_t ROP, mpf_t OP)
  411.      Set the value of ROP from OP.
  412.  - Function: int mpz_set_str (mpz_t ROP, char *STR, int BASE)
  413.      Set the value of ROP from STR, a '\0'-terminated C string in base
  414.      BASE.  White space is allowed in the string, and is simply
  415.      ignored.  The base may vary from 2 to 36.  If BASE is 0, the
  416.      actual base is determined from the leading characters: if the
  417.      first two characters are `0x' or `0X', hexadecimal is assumed,
  418.      otherwise if the first character is `0', octal is assumed,
  419.      otherwise decimal is assumed.
  420.      This function returns 0 if the entire string up to the '\0' is a
  421.      valid number in base BASE.  Otherwise it returns -1.
  422. File: gmp.info,  Node: Simultaneous Integer Init & Assign,  Next: Converting Integers,  Prev: Assigning Integers,  Up: Integer Functions
  423. Combined Initialization and Assignment Functions
  424. ------------------------------------------------
  425.    For convenience, MP provides a parallel series of initialize-and-set
  426. functions which initialize the output and then store the value there.
  427. These functions' names have the form `mpz_init_set...'
  428.    Here is an example of using one:
  429.      {
  430.        mpz_t pie;
  431.        mpz_init_set_str (pie, "3141592653589793238462643383279502884", 10);
  432.        ...
  433.        mpz_sub (pie, ...);
  434.        ...
  435.        mpz_clear (pie);
  436.      }
  437. Once the integer has been initialized by any of the `mpz_init_set...'
  438. functions, it can be used as the source or destination operand for the
  439. ordinary integer functions.  Don't use an initialize-and-set function
  440. on a variable already initialized!
  441.  - Function: void mpz_init_set (mpz_t ROP, mpz_t OP)
  442.  - Function: void mpz_init_set_ui (mpz_t ROP, unsigned long int OP)
  443.  - Function: void mpz_init_set_si (mpz_t ROP, signed long int OP)
  444.  - Function: void mpz_init_set_d (mpz_t ROP, double OP)
  445.      Initialize ROP with limb space and set the initial numeric value
  446.      from OP.
  447.  - Function: int mpz_init_set_str (mpz_t ROP, char *STR, int BASE)
  448.      Initialize ROP and set its value like `mpz_set_str' (see its
  449.      documentation above for details).
  450.      If the string is a correct base BASE number, the function returns
  451.      0; if an error occurs it returns -1.  ROP is initialized even if
  452.      an error occurs.  (I.e., you have to call `mpz_clear' for it.)
  453. File: gmp.info,  Node: Converting Integers,  Next: Integer Arithmetic,  Prev: Simultaneous Integer Init & Assign,  Up: Integer Functions
  454. Conversion Functions
  455. ====================
  456.    This section describes functions for converting arbitrary precision
  457. integers to standard C types.  Functions for converting *to* arbitrary
  458. precision integers are described in *Note Assigning Integers:: and
  459. *Note I/O of Integers::.
  460.  - Function: unsigned long int mpz_get_ui (mpz_t OP)
  461.      Return the least significant part from OP.  This function combined
  462.      with
  463.      `mpz_tdiv_q_2exp(..., OP, CHAR_BIT*sizeof(unsigned long int))' can
  464.      be used to extract the limbs of an integer.
  465.  - Function: signed long int mpz_get_si (mpz_t OP)
  466.      If OP fits into a `signed long int' return the value of OP.
  467.      Otherwise return the least significant part of OP, with the same
  468.      sign as OP.
  469.      If OP is too large to fit in a `signed long int', the returned
  470.      result is probably not very useful.
  471.  - Function: double mpz_get_d (mpz_t OP)
  472.      Convert OP to a double.
  473.  - Function: char * mpz_get_str (char *STR, int BASE, mpz_t OP)
  474.      Convert OP to a string of digits in base BASE.  The base may vary
  475.      from 2 to 36.
  476.      If STR is NULL, space for the result string is allocated using the
  477.      default allocation function, and a pointer to the string is
  478.      returned.
  479.      If STR is not NULL, it should point to a block of storage enough
  480.      large for the result.  To find out the right amount of space to
  481.      provide for STR, use `mpz_sizeinbase (OP, BASE) + 2'.  The two
  482.      extra bytes are for a possible minus sign, and for the terminating
  483.      null character.
  484. File: gmp.info,  Node: Integer Arithmetic,  Next: Comparison Functions,  Prev: Converting Integers,  Up: Integer Functions
  485. Arithmetic Functions
  486. ====================
  487.  - Function: void mpz_add (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  488.  - Function: void mpz_add_ui (mpz_t ROP, mpz_t OP1, unsigned long int
  489.           OP2)
  490.      Set ROP to OP1 + OP2.
  491.  - Function: void mpz_sub (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  492.  - Function: void mpz_sub_ui (mpz_t ROP, mpz_t OP1, unsigned long int
  493.           OP2)
  494.      Set ROP to OP1 - OP2.
  495.  - Function: void mpz_mul (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  496.  - Function: void mpz_mul_ui (mpz_t ROP, mpz_t OP1, unsigned long int
  497.           OP2)
  498.      Set ROP to OP1 times OP2.
  499.  - Function: void mpz_mul_2exp (mpz_t ROP, mpz_t OP1, unsigned long int
  500.           OP2)
  501.      Set ROP to OP1 times 2 raised to OP2.  This operation can also be
  502.      defined as a left shift, OP2 steps.
  503.  - Function: void mpz_neg (mpz_t ROP, mpz_t OP)
  504.      Set ROP to -OP.
  505.  - Function: void mpz_abs (mpz_t ROP, mpz_t OP)
  506.      Set ROP to the absolute value of OP.
  507.  - Function: void mpz_fac_ui (mpz_t ROP, unsigned long int OP)
  508.      Set ROP to OP!, the factorial of OP.
  509. Division functions
  510. ------------------
  511.    Division is undefined if the divisor is zero, and passing a zero
  512. divisor to the divide or modulo functions, as well passing a zero mod
  513. argument to the `mpz_powm' and `mpz_powm_ui' functions, will make these
  514. functions intentionally divide by zero.  This gives the user the
  515. possibility to handle arithmetic exceptions in these functions in the
  516. same manner as other arithmetic exceptions.
  517.    There are three main groups of division functions:
  518.    * Functions that truncate the quotient towards 0.  The names of these
  519.      functions start with `mpz_tdiv'.  The `t' in the name is short for
  520.      `truncate'.
  521.    * Functions that round the quotient towards -infinity.  The names of
  522.      these routines start with `mpz_fdiv'.  The `f' in the name is
  523.      short for `floor'.
  524.    * Functions that round the quotient towards +infinity.  The names of
  525.      these routines start with `mpz_cdiv'.  The `c' in the name is
  526.      short for `ceil'.
  527.    For each rounding mode, there are a couple of variants.  Here `q'
  528. means that the quotient is computed, while `r' means that the remainder
  529. is computed.  Functions that compute both the quotient and remainder
  530. have `qr' in the name.
  531.  - Function: void mpz_tdiv_q (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  532.  - Function: void mpz_tdiv_q_ui (mpz_t ROP, mpz_t OP1, unsigned long
  533.           int OP2)
  534.      Set ROP to [OP1/OP2].  The quotient is truncated towards 0.
  535.  - Function: void mpz_tdiv_r (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  536.  - Function: void mpz_tdiv_r_ui (mpz_t ROP, mpz_t OP1, unsigned long
  537.           int OP2)
  538.      Set ROP to (OP1 - [OP1/OP2] * OP2).  Unless the remainder is zero,
  539.      it has the same sign as the dividend.
  540.  - Function: void mpz_tdiv_qr (mpz_t ROP1, mpz_t ROP2, mpz_t OP1, mpz_t
  541.           OP2)
  542.  - Function: void mpz_tdiv_qr_ui (mpz_t ROP1, mpz_t ROP2, mpz_t OP1,
  543.           unsigned long int OP2)
  544.      Divide OP1 by OP2 and put the quotient in ROP1 and the remainder
  545.      in ROP2.  The quotient is rounded towards 0.  Unless the remainder
  546.      is zero, it has the same sign as the dividend.
  547.      If ROP1 and ROP2 are the same variable, the results are undefined.
  548.  - Function: void mpz_fdiv_q (mpz_t ROP1, mpz_t OP1, mpz_t OP2)
  549.  - Function: void mpz_fdiv_q_ui (mpz_t ROP, mpz_t OP1, unsigned long
  550.           int OP2)
  551.      Set ROP to OP1/OP2.  The quotient is rounded towards -infinity.
  552.  - Function: void mpz_fdiv_r (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  553.  - Function: unsigned long int mpz_fdiv_r_ui (mpz_t ROP, mpz_t OP1,
  554.           unsigned long int OP2)
  555.      Divide OP1 by OP2 and put the remainder in ROP.  Unless the
  556.      remainder is zero, it has the same sign as the divisor.
  557.      For `mpz_fdiv_r_ui' the remainder is small enough to fit in an
  558.      `unsigned long int', and is therefore returned.
  559.  - Function: void mpz_fdiv_qr (mpz_t ROP1, mpz_t ROP2, mpz_t OP1, mpz_t
  560.           OP2)
  561.  - Function: unsigned long int mpz_fdiv_qr_ui (mpz_t ROP1, mpz_t ROP2,
  562.           mpz_t OP1, unsigned long int OP2)
  563.      Divide OP1 by OP2 and put the quotient in ROP1 and the remainder
  564.      in ROP2.  The quotient is rounded towards -infinity.  Unless the
  565.      remainder is zero, it has the same sign as the divisor.
  566.      For `mpz_fdiv_qr_ui' the remainder is small enough to fit in an
  567.      `unsigned long int', and is therefore returned.
  568.      If ROP1 and ROP2 are the same variable, the results are undefined.
  569.  - Function: unsigned long int mpz_fdiv_ui (mpz_t OP1, unsigned long
  570.           int OP2)
  571.      This function is similar to `mpz_fdiv_r_ui', but the remainder is
  572.      only returned; it is not stored anywhere.
  573.  - Function: void mpz_cdiv_q (mpz_t ROP1, mpz_t OP1, mpz_t OP2)
  574.  - Function: void mpz_cdiv_q_ui (mpz_t ROP, mpz_t OP1, unsigned long
  575.           int OP2)
  576.      Set ROP to OP1/OP2.  The quotient is rounded towards +infinity.
  577.  - Function: void mpz_cdiv_r (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  578.  - Function: unsigned long int mpz_cdiv_r_ui (mpz_t ROP, mpz_t OP1,
  579.           unsigned long int OP2)
  580.      Divide OP1 by OP2 and put the remainder in ROP.  Unless the
  581.      remainder is zero, it has the opposite sign as the divisor.
  582.      For `mpz_cdiv_r_ui' the negated remainder is small enough to fit
  583.      in an `unsigned long int', and it is therefore returned.
  584.  - Function: void mpz_cdiv_qr (mpz_t ROP1, mpz_t ROP2, mpz_t OP1, mpz_t
  585.           OP2)
  586.  - Function: unsigned long int mpz_cdiv_qr_ui (mpz_t ROP1, mpz_t ROP2,
  587.           mpz_t OP1, unsigned long int OP2)
  588.      Divide OP1 by OP2 and put the quotient in ROP1 and the remainder
  589.      in ROP2.  The quotient is rounded towards +infinity.  Unless the
  590.      remainder is zero, it has the opposite sign as the divisor.
  591.      For `mpz_cdiv_qr_ui' the negated remainder is small enough to fit
  592.      in an `unsigned long int', and it is therefore returned.
  593.      If ROP1 and ROP2 are the same variable, the results are undefined.
  594.  - Function: unsigned long int mpz_cdiv_ui (mpz_t OP1, unsigned long
  595.           int OP2)
  596.      Return the negated remainder, similar to `mpz_cdiv_r_ui'.  (The
  597.      difference is that this function doesn't store the remainder
  598.      anywhere.)
  599.  - Function: void mpz_mod (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  600.  - Function: unsigned long int mpz_mod_ui (mpz_t ROP, mpz_t OP1,
  601.           unsigned long int OP2)
  602.      Set ROP to OP1 `mod' OP2.  The sign of the divisor is ignored, and
  603.      the result is always non-negative.
  604.      For `mpz_mod_ui' the remainder is small enough to fit in an
  605.      `unsigned long int', and is therefore returned.
  606.  - Function: void mpz_divexact (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  607.      Set ROP to OP1/OP2.  This function produces correct results only
  608.      when it is known in advance that OP2 divides OP1.
  609.      Since mpz_divexact is much faster than any of the other routines
  610.      that produce the quotient (*note References::. Jebelean), it is
  611.      the best choice for instances in which exact division is known to
  612.      occur, such as reducing a rational to lowest terms.
  613.  - Function: void mpz_tdiv_q_2exp (mpz_t ROP, mpz_t OP1, unsigned long
  614.           int OP2)
  615.      Set ROP to OP1 divided by 2 raised to OP2.  The quotient is
  616.      rounded towards 0.
  617.  - Function: void mpz_tdiv_r_2exp (mpz_t ROP, mpz_t OP1, unsigned long
  618.           int OP2)
  619.      Divide OP1 by (2 raised to OP2) and put the remainder in ROP.
  620.      Unless it is zero, ROP will have the same sign as OP1.
  621.  - Function: void mpz_fdiv_q_2exp (mpz_t ROP, mpz_t OP1, unsigned long
  622.           int OP2)
  623.      Set ROP to OP1 divided by 2 raised to OP2.  The quotient is
  624.      rounded towards -infinity.
  625.  - Function: void mpz_fdiv_r_2exp (mpz_t ROP, mpz_t OP1, unsigned long
  626.           int OP2)
  627.      Divide OP1 by (2 raised to OP2) and put the remainder in ROP.  The
  628.      sign of ROP will always be positive.
  629.      This operation can also be defined as masking of the OP2 least
  630.      significant bits.
  631. Exponentialization Functions
  632. ----------------------------
  633.  - Function: void mpz_powm (mpz_t ROP, mpz_t BASE, mpz_t EXP, mpz_t MOD)
  634.  - Function: void mpz_powm_ui (mpz_t ROP, mpz_t BASE, unsigned long int
  635.           EXP, mpz_t MOD)
  636.      Set ROP to (BASE raised to EXP) `mod' MOD.  If EXP is negative,
  637.      the result is undefined.
  638.  - Function: void mpz_pow_ui (mpz_t ROP, mpz_t BASE, unsigned long int
  639.           EXP)
  640.  - Function: void mpz_ui_pow_ui (mpz_t ROP, unsigned long int BASE,
  641.           unsigned long int EXP)
  642.      Set ROP to BASE raised to EXP.  The case of 0^0 yields 1.
  643. Square Root Functions
  644. ---------------------
  645.  - Function: void mpz_sqrt (mpz_t ROP, mpz_t OP)
  646.      Set ROP to the truncated integer part of the square root of OP.
  647.  - Function: void mpz_sqrtrem (mpz_t ROP1, mpz_t ROP2, mpz_t OP)
  648.      Set ROP1 to the truncated integer part of the square root of OP,
  649.      like `mpz_sqrt'.  Set ROP2 to OP-ROP1*ROP1, (i.e., zero if OP is a
  650.      perfect square).
  651.      If ROP1 and ROP2 are the same variable, the results are undefined.
  652.  - Function: int mpz_perfect_square_p (mpz_t OP)
  653.      Return non-zero if OP is a perfect square, i.e., if the square
  654.      root of OP is an integer.  Return zero otherwise.
  655. Number Theoretic Functions
  656. --------------------------
  657.  - Function: int mpz_probab_prime_p (mpz_t OP, int REPS)
  658.      If this function returns 0, OP is definitely not prime.  If it
  659.      returns 1, then OP is `probably' prime.  The probability of a
  660.      false positive is (1/4)**REPS.  A reasonable value of reps is 25.
  661.      An implementation of the probabilistic primality test found in
  662.      Seminumerical Algorithms (*note References::. Knuth).
  663.  - Function: void mpz_gcd (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  664.      Set ROP to the greatest common divisor of OP1 and OP2.
  665.  - Function: unsigned long int mpz_gcd_ui (mpz_t ROP, mpz_t OP1,
  666.           unsigned long int OP2)
  667.      Compute the greatest common divisor of OP1 and OP2.  If ROP is not
  668.      NULL, store the result there.
  669.      If the result is small enough to fit in an `unsigned long int', it
  670.      is returned.  If the result does not fit, 0 is returned, and the
  671.      result is equal to the argument OP1.  Note that the result will
  672.      always fit if OP2 is non-zero.
  673.  - Function: void mpz_gcdext (mpz_t G, mpz_t S, mpz_t T, mpz_t A, mpz_t
  674.           B)
  675.      Compute G, S, and T, such that AS + BT = G = `gcd' (A, B).  If T is
  676.      NULL, that argument is not computed.
  677.  - Function: int mpz_invert (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  678.      Compute the inverse of OP1 modulo OP2 and put the result in ROP.
  679.      Return non-zero if an inverse exist, zero otherwise.  When the
  680.      function returns zero, do not assume anything about the value in
  681.      ROP.
  682.  - Function: int mpz_jacobi (mpz_t OP1, mpz_t OP2)
  683.  - Function: int mpz_legendre (mpz_t OP1, mpz_t OP2)
  684.      Compute the Jacobi and Legendre symbols, respectively.
  685. File: gmp.info,  Node: Comparison Functions,  Next: Integer Logic and Bit Fiddling,  Prev: Integer Arithmetic,  Up: Integer Functions
  686. Comparison Functions
  687. ====================
  688.  - Function: int mpz_cmp (mpz_t OP1, mpz_t OP2)
  689.      Compare OP1 and OP2.  Return a positive value if OP1 > OP2, zero
  690.      if OP1 = OP2, and a negative value if OP1 < OP2.
  691.  - Macro: int mpz_cmp_ui (mpz_t OP1, unsigned long int OP2)
  692.  - Macro: int mpz_cmp_si (mpz_t OP1, signed long int OP2)
  693.      Compare OP1 and OP2.  Return a positive value if OP1 > OP2, zero
  694.      if OP1 = OP2, and a negative value if OP1 < OP2.
  695.      These functions are actually implemented as macros.  They evaluate
  696.      their arguments multiple times.
  697.  - Macro: int mpz_sgn (mpz_t OP)
  698.      Return +1 if OP > 0, 0 if OP = 0, and -1 if OP < 0.
  699.      This function is actually implemented as a macro.  It evaluates its
  700.      arguments multiple times.
  701. File: gmp.info,  Node: Integer Logic and Bit Fiddling,  Next: I/O of Integers,  Prev: Comparison Functions,  Up: Integer Functions
  702. Logical and Bit Manipulation Functions
  703. ======================================
  704.    These functions behave as if two's complement arithmetic were used
  705. (although sign-magnitude is used by the actual implementation).
  706.  - Function: void mpz_and (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  707.      Set ROP to OP1 logical-and OP2.
  708.  - Function: void mpz_ior (mpz_t ROP, mpz_t OP1, mpz_t OP2)
  709.      Set ROP to OP1 inclusive-or OP2.
  710.  - Function: void mpz_com (mpz_t ROP, mpz_t OP)
  711.      Set ROP to the one's complement of OP.
  712.  - Function: unsigned long int mpz_popcount (mpz_t OP)
  713.      For non-negative numbers, return the population count of OP.  For
  714.      negative numbers, return the largest possible value (MAX_ULONG).
  715.  - Function: unsigned long int mpz_hamdist (mpz_t OP1, mpz_t OP2)
  716.      If OP1 and OP2 are both non-negative, return the hamming distance
  717.      between the two operands.  Otherwise, return the largest possible
  718.      value (MAX_ULONG).
  719.      It is possible to extend this function to return a useful value
  720.      when the operands are both negative, but the current
  721.      implementation returns MAX_ULONG in this case.  *Do not depend on
  722.      this behavior, since it will change in future versions of the
  723.      library.*
  724.  - Function: unsigned long int mpz_scan0 (mpz_t OP, unsigned long int
  725.           STARTING_BIT)
  726.      Scan OP, starting with bit STARTING_BIT, towards more significant
  727.      bits, until the first clear bit is found.  Return the index of the
  728.      found bit.
  729.  - Function: unsigned long int mpz_scan1 (mpz_t OP, unsigned long int
  730.           STARTING_BIT)
  731.      Scan OP, starting with bit STARTING_BIT, towards more significant
  732.      bits, until the first set bit is found.  Return the index of the
  733.      found bit.
  734.  - Function: void mpz_setbit (mpz_t ROP, unsigned long int BIT_INDEX)
  735.      Set bit BIT_INDEX in OP1.
  736.  - Function: void mpz_clrbit (mpz_t ROP, unsigned long int BIT_INDEX)
  737.      Clear bit BIT_INDEX in OP1.
  738. File: gmp.info,  Node: I/O of Integers,  Next: Miscellaneous Integer Functions,  Prev: Integer Logic and Bit Fiddling,  Up: Integer Functions
  739. Input and Output Functions
  740. ==========================
  741.    Functions that perform input from a stdio stream, and functions that
  742. output to a stdio stream.  Passing a NULL pointer for a STREAM argument
  743. to any of these functions will make them read from `stdin' and write to
  744. `stdout', respectively.
  745.    When using any of these functions, it is a good idea to include
  746. `stdio.h' before `gmp.h', since that will allow `gmp.h' to define
  747. prototypes for these functions.
  748.  - Function: size_t mpz_out_str (FILE *STREAM, int BASE, mpz_t OP)
  749.      Output OP on stdio stream STREAM, as a string of digits in base
  750.      BASE.  The base may vary from 2 to 36.
  751.      Return the number of bytes written, or if an error occurred,
  752.      return 0.
  753.  - Function: size_t mpz_inp_str (mpz_t ROP, FILE *STREAM, int BASE)
  754.      Input a possibly white-space preceded string in base BASE from
  755.      stdio stream STREAM, and put the read integer in ROP.  The base
  756.      may vary from 2 to 36.  If BASE is 0, the actual base is
  757.      determined from the leading characters: if the first two
  758.      characters are `0x' or `0X', hexadecimal is assumed, otherwise if
  759.      the first character is `0', octal is assumed, otherwise decimal is
  760.      assumed.
  761.      Return the number of bytes read, or if an error occurred, return 0.
  762.  - Function: size_t mpz_out_raw (FILE *STREAM, mpz_t OP)
  763.      Output OP on stdio stream STREAM, in raw binary format.  The
  764.      integer is written in a portable format, with 4 bytes of size
  765.      information, and that many bytes of limbs.  Both the size and the
  766.      limbs are written in decreasing significance order (i.e., in
  767.      big-endian).
  768.      The output can be read with `mpz_inp_raw'.
  769.      Return the number of bytes written, or if an error occurred,
  770.      return 0.
  771.      The output of this can not be read by `mpz_inp_raw' from GMP 1,
  772.      because of changes necessary for compatibility between 32-bit and
  773.      64-bit machines.
  774.  - Function: size_t mpz_inp_raw (mpz_t ROP, FILE *STREAM)
  775.      Input from stdio stream STREAM in the format written by
  776.      `mpz_out_raw', and put the result in ROP.  Return the number of
  777.      bytes read, or if an error occurred, return 0.
  778.      This routine can read the output from `mpz_out_raw' also from GMP
  779.      1, in spite of changes necessary for compatibility between 32-bit
  780.      and 64-bit machines.
  781. File: gmp.info,  Node: Miscellaneous Integer Functions,  Prev: I/O of Integers,  Up: Integer Functions
  782. Miscellaneous Functions
  783. =======================
  784.  - Function: void mpz_random (mpz_t ROP, mp_size_t MAX_SIZE)
  785.      Generate a random integer of at most MAX_SIZE limbs.  The generated
  786.      random number doesn't satisfy any particular requirements of
  787.      randomness.  Negative random numbers are generated when MAX_SIZE
  788.      is negative.
  789.  - Function: void mpz_random2 (mpz_t ROP, mp_size_t MAX_SIZE)
  790.      Generate a random integer of at most MAX_SIZE limbs, with long
  791.      strings of zeros and ones in the binary representation.  Useful
  792.      for testing functions and algorithms, since this kind of random
  793.      numbers have proven to be more likely to trigger corner-case bugs.
  794.      Negative random numbers are generated when MAX_SIZE is negative.
  795.  - Function: size_t mpz_size (mpz_t OP)
  796.      Return the size of OP measured in number of limbs.  If OP is zero,
  797.      the returned value will be zero.
  798.      *This function is obsolete.  It will disappear from future MP
  799.      releases.*
  800.  - Function: size_t mpz_sizeinbase (mpz_t OP, int BASE)
  801.      Return the size of OP measured in number of digits in base BASE.
  802.      The base may vary from 2 to 36.  The returned value will be exact
  803.      or 1 too big.  If BASE is a power of 2, the returned value will
  804.      always be exact.
  805.      This function is useful in order to allocate the right amount of
  806.      space before converting OP to a string.  The right amount of
  807.      allocation is normally two more than the value returned by
  808.      `mpz_sizeinbase' (one extra for a minus sign and one for the
  809.      terminating '\0').
  810. File: gmp.info,  Node: Rational Number Functions,  Next: Floating-point Functions,  Prev: Integer Functions,  Up: Top
  811. Rational Number Functions
  812. *************************
  813.    This chapter describes the MP functions for performing arithmetic on
  814. rational numbers.  These functions start with the prefix `mpq_'.
  815.    Rational numbers are stored in objects of type `mpq_t'.
  816.    All rational arithmetic functions assume operands have a canonical
  817. form, and canonicalize their result.  The canonical from means that the
  818. denominator and the numerator have no common factors, and that the
  819. denominator is positive.  Zero has the unique representation 0/1.
  820.    Pure assignment functions do not canonicalize the assigned variable.
  821. It is the responsibility of the user to canonicalize the assigned
  822. variable before any arithmetic operations are performed on that
  823. variable.  *Note that this is an incompatible change from version 1 of
  824. the library.*
  825.  - Function: void mpq_canonicalize (mpq_t OP)
  826.      Remove any factors that are common to the numerator and
  827.      denominator of OP, and make the denominator positive.
  828. * Menu:
  829. * Initializing Rationals::
  830. * Assigning Rationals::
  831. * Simultaneous Integer Init & Assign::
  832. * Comparing Rationals::
  833. * Applying Integer Functions::
  834. * Miscellaneous Rational Functions::
  835. File: gmp.info,  Node: Initializing Rationals,  Next: Assigning Rationals,  Prev: Rational Number Functions,  Up: Rational Number Functions
  836. Initialization and Assignment Functions
  837. =======================================
  838.  - Function: void mpq_init (mpq_t DEST_RATIONAL)
  839.      Initialize DEST_RATIONAL and set it to 0/1.  Each variable should
  840.      normally only be initialized once, or at least cleared out (using
  841.      the function `mpq_clear') between each initialization.
  842.  - Function: void mpq_clear (mpq_t RATIONAL_NUMBER)
  843.      Free the space occupied by RATIONAL_NUMBER.  Make sure to call this
  844.      function for all `mpq_t' variables when you are done with them.
  845.  - Function: void mpq_set (mpq_t ROP, mpq_t OP)
  846.  - Function: void mpq_set_z (mpq_t ROP, mpz_t OP)
  847.      Assign ROP from OP.
  848.  - Function: void mpq_set_ui (mpq_t ROP, unsigned long int OP1,
  849.           unsigned long int OP2)
  850.  - Function: void mpq_set_si (mpq_t ROP, signed long int OP1, unsigned
  851.           long int OP2)
  852.      Set the value of ROP to OP1/OP2.  Note that if OP1 and OP2 have
  853.      common factors, ROP has to be passed to `mpq_canonicalize' before
  854.      any operations are performed on ROP.
  855. File: gmp.info,  Node: Assigning Rationals,  Next: Comparing Rationals,  Prev: Initializing Rationals,  Up: Rational Number Functions
  856. Arithmetic Functions
  857. ====================
  858.  - Function: void mpq_add (mpq_t SUM, mpq_t ADDEND1, mpq_t ADDEND2)
  859.      Set SUM to ADDEND1 + ADDEND2.
  860.  - Function: void mpq_sub (mpq_t DIFFERENCE, mpq_t MINUEND, mpq_t
  861.           SUBTRAHEND)
  862.      Set DIFFERENCE to MINUEND - SUBTRAHEND.
  863.  - Function: void mpq_mul (mpq_t PRODUCT, mpq_t MULTIPLIER, mpq_t
  864.           MULTIPLICAND)
  865.      Set PRODUCT to MULTIPLIER times MULTIPLICAND.
  866.  - Function: void mpq_div (mpq_t QUOTIENT, mpq_t DIVIDEND, mpq_t
  867.           DIVISOR)
  868.      Set QUOTIENT to DIVIDEND/DIVISOR.
  869.  - Function: void mpq_neg (mpq_t NEGATED_OPERAND, mpq_t OPERAND)
  870.      Set NEGATED_OPERAND to -OPERAND.
  871.  - Function: void mpq_inv (mpq_t INVERTED_NUMBER, mpq_t NUMBER)
  872.      Set INVERTED_NUMBER to 1/NUMBER.  If the new denominator is zero,
  873.      this routine will divide by zero.
  874. File: gmp.info,  Node: Comparing Rationals,  Next: Applying Integer Functions,  Prev: Assigning Rationals,  Up: Rational Number Functions
  875. Comparison Functions
  876. ====================
  877.  - Function: int mpq_cmp (mpq_t OP1, mpq_t OP2)
  878.      Compare OP1 and OP2.  Return a positive value if OP1 > OP2, zero
  879.      if OP1 = OP2, and a negative value if OP1 < OP2.
  880.      To determine if two rationals are equal, `mpq_equal' is faster than
  881.      `mpq_cmp'.
  882.  - Macro: int mpq_cmp_ui (mpq_t OP1, unsigned long int NUM2, unsigned
  883.           long int DEN2)
  884.      Compare OP1 and NUM2/DEN2.  Return a positive value if OP1 >
  885.      NUM2/DEN2, zero if OP1 = NUM2/DEN2, and a negative value if OP1 <
  886.      NUM2/DEN2.
  887.      This routine allows that NUM2 and DEN2 have common factors.
  888.      This function is actually implemented as a macro.  It evaluates its
  889.      arguments multiple times.
  890.  - Macro: int mpq_sgn (mpq_t OP)
  891.      Return +1 if OP > 0, 0 if OP = 0, and -1 if OP < 0.
  892.      This function is actually implemented as a macro.  It evaluates its
  893.      arguments multiple times.
  894.  - Function: int mpq_equal (mpq_t OP1, mpq_t OP2)
  895.      Return non-zero if OP1 and OP2 are equal, zero if they are
  896.      non-equal.  Although `mpq_cmp' can be used for the same purpose,
  897.      this function is much faster.
  898. File: gmp.info,  Node: Applying Integer Functions,  Next: Miscellaneous Rational Functions,  Prev: Comparing Rationals,  Up: Rational Number Functions
  899. Applying Integer Functions to Rationals
  900. =======================================
  901.    The set of `mpq' functions is quite small.  In particular, there are
  902. no functions for either input or output.  But there are two macros that
  903. allow us to apply any `mpz' function on the numerator or denominator of
  904. a rational number.  If these macros are used to assign to the rational
  905. number, `mpq_canonicalize' normally need to be called afterwards.
  906.  - Macro: mpz_t mpq_numref (mpq_t OP)
  907.  - Macro: mpz_t mpq_denref (mpq_t OP)
  908.      Return a reference to the numerator and denominator of OP,
  909.      respectively.  The `mpz' functions can be used on the result of
  910.      these macros.
  911. File: gmp.info,  Node: Miscellaneous Rational Functions,  Prev: Applying Integer Functions,  Up: Rational Number Functions
  912. Miscellaneous Functions
  913. =======================
  914.  - Function: double mpq_get_d (mpq_t OP)
  915.      Convert OP to a double.
  916.    These functions assign between either the numerator or denominator
  917. of a rational, and an integer.  Instead of using these functions, it is
  918. preferable to use the more general mechanisms `mpq_numref' and
  919. `mpq_denref', together with `mpz_set'.
  920.  - Function: void mpq_set_num (mpq_t RATIONAL, mpz_t NUMERATOR)
  921.      Copy NUMERATOR to the numerator of RATIONAL.  When this risks to
  922.      make the numerator and denominator of RATIONAL have common
  923.      factors, you have to pass RATIONAL to `mpq_canonicalize' before
  924.      any operations are performed on RATIONAL.
  925.      This function is equivalent to `mpz_set (mpq_numref (RATIONAL),
  926.      NUMERATOR)'.
  927.  - Function: void mpq_set_den (mpq_t RATIONAL, mpz_t DENOMINATOR)
  928.      Copy DENOMINATOR to the denominator of RATIONAL.  When this risks
  929.      to make the numerator and denominator of RATIONAL have common
  930.      factors, or if the denominator might be negative, you have to pass
  931.      RATIONAL to `mpq_canonicalize' before any operations are performed
  932.      on RATIONAL.
  933.      *In version 1 of the library, negative denominators were handled by
  934.      copying the sign to the numerator.  That is no longer done.*
  935.      This function is equivalent to `mpz_set (mpq_denref (RATIONAL),
  936.      DENOMINATORS)'.
  937.  - Function: void mpq_get_num (mpz_t NUMERATOR, mpq_t RATIONAL)
  938.      Copy the numerator of RATIONAL to the integer NUMERATOR, to
  939.      prepare for integer operations on the numerator.
  940.      This function is equivalent to `mpz_set (NUMERATOR, mpq_numref
  941.      (RATIONAL))'.
  942.  - Function: void mpq_get_den (mpz_t DENOMINATOR, mpq_t RATIONAL)
  943.      Copy the denominator of RATIONAL to the integer DENOMINATOR, to
  944.      prepare for integer operations on the denominator.
  945.      This function is equivalent to `mpz_set (DENOMINATOR, mpq_denref
  946.      (RATIONAL))'.
  947.